<!doctype html>
<html class="theme-next use-motion theme-next-mist">
<head>
  
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

  <meta name="google-site-verification" content="K8DCBviaoTBKVs28YBB7IBIbospQ9RVlgSh81RYMUhY" />


  <meta name="baidu-site-verification" content="tXr3ZTm3Hx" />



  <link rel="stylesheet" type="text/css" href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5"/>


<link rel="stylesheet" type="text/css" href="/css/main.css?v=0.4.5.1"/>

  <meta name="description" content="xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native." />


  <meta name="keywords" content="git,git hook,代码规范," />


  <link rel="alternate" target="_blank" href="/atom.xml" title="xgfe" type="application/atom+xml" />


  <link rel="shorticon icon" type="image/x-icon" href="http://p0.meituan.net/xgfe/2db359f56ce13be30dedef160e0e57ce16958.ico?v=0.4.5.1" />

<meta name="description" content="xgfe团队已经定制了自己的html的编码规范，对应的html规范检查工具xg-htmlhint。以后也会有对应的js, css, sass编码规范和检查工具诞生，但是规范的制定和执行是两码事儿，而且往往存在很大的不对等。虽然辅以强大的编辑器插件我们可以做到在文件保存时做规范检查和提醒，但这样一来可能会打断思路，再者多多少少可以被轻易绕过。所以本文介绍引入git commit hook，在本地Co">
<meta name="keywords" content="git,git hook,代码规范">
<meta property="og:type" content="article">
<meta property="og:title" content="git commit hook">
<meta property="og:url" content="http://xgfe.github.io/2015/10/28/felix/git-commit-hook/index.html">
<meta property="og:site_name" content="xgfe">
<meta property="og:description" content="xgfe团队已经定制了自己的html的编码规范，对应的html规范检查工具xg-htmlhint。以后也会有对应的js, css, sass编码规范和检查工具诞生，但是规范的制定和执行是两码事儿，而且往往存在很大的不对等。虽然辅以强大的编辑器插件我们可以做到在文件保存时做规范检查和提醒，但这样一来可能会打断思路，再者多多少少可以被轻易绕过。所以本文介绍引入git commit hook，在本地Co">
<meta property="og:updated_time" content="2017-04-12T08:03:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="git commit hook">
<meta name="twitter:description" content="xgfe团队已经定制了自己的html的编码规范，对应的html规范检查工具xg-htmlhint。以后也会有对应的js, css, sass编码规范和检查工具诞生，但是规范的制定和执行是两码事儿，而且往往存在很大的不对等。虽然辅以强大的编辑器插件我们可以做到在文件保存时做规范检查和提醒，但这样一来可能会打断思路，再者多多少少可以被轻易绕过。所以本文介绍引入git commit hook，在本地Co">


<script type="text/javascript" id="hexo.configuration">
  var CONFIG = {
    scheme: 'Mist',
    sidebar: 'post'
  };
</script>

  <title> git commit hook | xgfe </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
  <div style="position: fixed; top: -9999px; left: -9999px;">
    <img src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe"/>
  </div>
  <!--[if lte IE 8]>
  <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;margin:0 auto;'>
    <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
      <img src="http://7u2nvr.com1.z0.glb.clouddn.com/picouterie.jpg" border="0" height="42" width="820"
           alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today or use other browser ,like chrome firefox safari."
           style='margin-left:auto;margin-right:auto;display: block;'/>
    </a>
  </div>
<![endif]-->
  

  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?3601d4483819a5ab6ddabb0b6422a328";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>



  <div class="container one-column page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><h1 class="site-meta">
  <span class="logo-line-before"><i></i></span>
  <a href="/" class="brand" rel="start">
      <span class="logo">
        <i class="icon-next-logo"></i>
      </span>
      <span class="site-title">xgfe</span>
  </a>
  <span class="logo-line-after"><i></i></span>
</h1>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  
  

  
    <ul id="menu" class="menu menu-left">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            <i class="menu-item-icon icon-next-home"></i> <br />
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            <i class="menu-item-icon icon-next-archives"></i> <br />
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            <i class="menu-item-icon icon-next-tags"></i> <br />
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-join">
          <a href="/join" rel="section">
            <i class="menu-item-icon icon-next-join"></i> <br />
            加入我们
          </a>
        </li>
      
      <!-- slide-links added by felix -->
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="http://xgfe.github.io/Basics/" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Basics
        </a>
      </li>
      <li class="menu-item menu-item-slides" style="opacity: 1; transform: translateY(0px);">
        <a href="https://slides.com/xgfe" target="_blank" rel="section">
          <i class="menu-item-icon icon-next-slides"></i> <br>
          Slides
        </a>
      </li>

      
      
    </ul>
  

  
    <div class="site-search">
      

    </div>
  

    <div class="site-search">
      <form class="site-search-form" id="gg-form" action="https://www.google.com/webhp" >
        <input type="text" name="q" id="gg-search-input" class="menu-search-input">
      </form>
    </div>
</nav>
 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div id="content" class="content"> 

  <div id="posts" class="posts-expand">
    

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">

      
      
        <h1 class="post-title" itemprop="name headline">
          
          
            
              git commit hook
            
          
        </h1>
      

      <div class="post-meta">
        <span class="post-time">
          发表于
          <time itemprop="dateCreated" datetime="2015-10-28T00:00:00+08:00" content="2015-10-28">
            2015-10-28
          </time>
        </span>

        
          <span class="post-category" >
            &nbsp; | &nbsp; 作者
            
              <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                <a href="/categories/felix/" itemprop="url" rel="index">
                  <span itemprop="name">felix</span>
                </a>
              </span>

              
              

            
          </span>
        

        
          
        

        <!-- tags 挪动位置 -->
        
          <span class="post-tags">
            &nbsp; | &nbsp;
            
              <a href="/tags/git/" rel="tag"><i class="icon-next-tags"></i>git</a>
            
              <a href="/tags/git-hook/" rel="tag"><i class="icon-next-tags"></i>git hook</a>
            
              <a href="/tags/代码规范/" rel="tag"><i class="icon-next-tags"></i>代码规范</a>
            
          </span>
        
      </div>
    </header>

    <div class="post-body">

      
      

      
        <span itemprop="articleBody"><p>xgfe团队已经定制了自己的html的编码规范，对应的html规范检查工具<a href="https://github.com/yangjiyuan/xg-htmlhint" target="_blank" rel="external">xg-htmlhint</a>。以后也会有对应的js, css, sass编码规范和检查工具诞生，但是规范的制定和执行是两码事儿，而且往往存在很大的不对等。虽然辅以强大的编辑器插件我们可以做到在文件保存时做规范检查和提醒，但这样一来可能会打断思路，再者多多少少可以被轻易绕过。所以本文介绍引入git commit hook，在本地Commit代码之前先进行代码规范检查，通过后才能进行Commit。<br><a id="more"></a></p>
<h1 id="Git-Hook"><a href="#Git-Hook" class="headerlink" title="Git Hook"></a>Git Hook</h1><p>Hook，又叫挂钩，在Git中被提供用来供开发人员在工作流中插入自定义脚本来一些进行相关的操作。在使用Git进行版本管理的项目中，在.git/hooks中可以看到这些文件，Git将他们改为了.sample的后缀以阻止其执行。在进行工作前，Git会先检查该工作流对应的是否挂钩存在，若存在则会先去执行挂钩上的脚本文件。在不同工作流中，Git要求hook脚本返回的值不同，有些地方需要hook脚本返回0才能继续进行工作，否则会中断该工作流，有些地方却不要求返回值，直接会继续进行工作流。因为Git是版本控制工具，存在客户端和服务端，在不同的端提供的hook也不同，下面分开进行简要介绍（由于hook比较多，在这里只介绍几个我们工作中可能使用到的，其他有兴趣的同学可以去官网看。Git hook地址：<a href="http://git-scm.com/docs/githooks" target="_blank" rel="external">http://git-scm.com/docs/githooks</a>)。</p>
<h2 id="pre-commit"><a href="#pre-commit" class="headerlink" title="pre-commit"></a>pre-commit</h2><p>pre-commit这个挂钩被 ‘git-commit’ 命令调用, 而且可以通过在命令中添加--no-verify 参数来跳过。这个挂钩没有参数，在得到提交消息后开始提交(commit)前被调用。如果挂钩执行结果是非零，那么 ‘git-commit’ 命令就会中止执行。这个挂钩就可以用来在本地代码提交前进行代码检查，符合则继续提交代码。</p>
<h2 id="pre-commit-示例代码"><a href="#pre-commit-示例代码" class="headerlink" title="pre-commit 示例代码"></a>pre-commit 示例代码</h2><p>附上pre-commit代码一份：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div></pre></td><td class="code"><pre><div class="line">#!/bin/sh</div><div class="line">#</div><div class="line"># An example hook script to verify what is about to be committed.</div><div class="line"># Called by &quot;git commit&quot; with no arguments.  The hook should</div><div class="line"># exit with non-zero status after issuing an appropriate message if</div><div class="line"># it wants to stop the commit.</div><div class="line">#</div><div class="line"># To enable this hook, rename this file to &quot;pre-commit&quot;.</div><div class="line"></div><div class="line">if git rev-parse --verify HEAD &gt;/dev/null 2&gt;&amp;1</div><div class="line">then</div><div class="line">        against=HEAD</div><div class="line">else</div><div class="line">        # Initial commit: diff against an empty tree object</div><div class="line">        against=4b825dc642cb6eb9a060e54bf8d69288fbee4904</div><div class="line">fi</div><div class="line"></div><div class="line"># If you want to allow non-ascii filenames set this variable to true.</div><div class="line">allownonascii=$(git config hooks.allownonascii)</div><div class="line"></div><div class="line"># Cross platform projects tend to avoid non-ascii filenames; prevent</div><div class="line"># them from being added to the repository. We exploit the fact that the</div><div class="line"># printable range starts at the space character and ends with tilde.</div><div class="line">if [ &quot;$allownonascii&quot; != &quot;true&quot; ] &amp;&amp;</div><div class="line">        # Note that the use of brackets around a tr range is ok here, (it&apos;s</div><div class="line">        # even required, for portability to Solaris 10&apos;s /usr/bin/tr), since</div><div class="line">        # the square bracket bytes happen to fall in the designated range.</div><div class="line">        test &quot;$(git diff --cached --name-only --diff-filter=A -z $against |</div><div class="line">          LC_ALL=C tr -d &apos;[ -~]\0&apos;)&quot;</div><div class="line">then</div><div class="line">        echo &quot;Error: Attempt to add a non-ascii file name.&quot;</div><div class="line">        echo</div><div class="line">        echo &quot;This can cause problems if you want to work&quot;</div><div class="line">        echo &quot;with people on other platforms.&quot;</div><div class="line">        echo</div><div class="line">        echo &quot;To be portable it is advisable to rename the file ...&quot;</div><div class="line">        echo</div><div class="line">        echo &quot;If you know what you are doing you can disable this&quot;</div><div class="line">        echo &quot;check using:&quot;</div><div class="line">        echo</div><div class="line">        echo &quot;  git config hooks.allownonascii true&quot;</div><div class="line">        echo</div><div class="line">        exit 1</div><div class="line">fi</div><div class="line"></div><div class="line">## Common</div><div class="line">EXIT_CODE=0</div><div class="line">REPO=$(pwd)</div><div class="line"></div><div class="line">#</div><div class="line"># Checking trailing whitespaces and indent</div><div class="line">#</div><div class="line"></div><div class="line">git diff --cached --check --color=always</div><div class="line">EXIT_STATUS=$?</div><div class="line">if [[ $EXIT_STATUS -ne 0 ]]; then</div><div class="line">    EXIT_CODE=$(($&#123;EXIT_CODE&#125; + $EXIT_STATUS))</div><div class="line">fi</div><div class="line"></div><div class="line">#</div><div class="line"># Begin htmlhint hook</div><div class="line">#</div><div class="line"></div><div class="line">HTMLHINT_BIN=htmlhint</div><div class="line">for FILE in `git diff-index --name-only $&#123;against&#125; -- | egrep .*\.html$`; do</div><div class="line"></div><div class="line">    if test -f $&#123;REPO&#125;/$&#123;FILE&#125;; then</div><div class="line">        $&#123;HTMLHINT_BIN&#125; $&#123;REPO&#125;/$&#123;FILE&#125;</div><div class="line">    else</div><div class="line">        continue</div><div class="line">    fi</div><div class="line"></div><div class="line">    # could similarly wrap Rhino or Node...</div><div class="line"></div><div class="line">    EXIT_CODE=$(($&#123;EXIT_CODE&#125; + $?))</div><div class="line">done</div><div class="line"># End htmlhint hook</div><div class="line"></div><div class="line"></div><div class="line">#</div><div class="line"># Begin JsHint hook</div><div class="line"># A pre-commit hook for git to lint JavaScript files with jshint</div><div class="line"># @see https://github.com/jshint/jshint/</div><div class="line">#</div><div class="line"></div><div class="line">JSHINT_BIN=jshint</div><div class="line">for FILE in `git diff-index --name-only $&#123;against&#125; -- | egrep .*\.js$`; do</div><div class="line"></div><div class="line">    if test -f $&#123;REPO&#125;/$&#123;FILE&#125;; then</div><div class="line">        $&#123;JSHINT_BIN&#125; $&#123;REPO&#125;/$&#123;FILE&#125;</div><div class="line">    else</div><div class="line">        continue</div><div class="line">    fi</div><div class="line"></div><div class="line">    # could similarly wrap Rhino or Node...</div><div class="line"></div><div class="line">    EXIT_CODE=$(($&#123;EXIT_CODE&#125; + $?))</div><div class="line">done</div><div class="line"># End JsHint hook</div><div class="line"></div><div class="line">#</div><div class="line"># Begin CssLint hook</div><div class="line">#</div><div class="line">CSSLINT_BIN=csslint</div><div class="line">for FILE in `git diff-index --name-only $&#123;against&#125; -- | egrep .*\.css$`; do</div><div class="line"></div><div class="line">    if test -f $&#123;REPO&#125;/$&#123;FILE&#125;; then</div><div class="line">        $&#123;CSSLINT_BIN&#125; $&#123;REPO&#125;/$&#123;FILE&#125;</div><div class="line">    else</div><div class="line">        continue</div><div class="line">    fi</div><div class="line"></div><div class="line"></div><div class="line">    # could similarly wrap Rhino or Node...</div><div class="line"></div><div class="line">    EXIT_CODE=$(($&#123;EXIT_CODE&#125; + $?))</div><div class="line">done</div><div class="line"># End CssLint hook</div><div class="line"></div><div class="line">#</div><div class="line"># Common</div><div class="line">#</div><div class="line"></div><div class="line">if [[ $&#123;EXIT_CODE&#125; -ne 0 ]]; then</div><div class="line">    echo &quot;&quot;</div><div class="line">    echo &quot;Problems were found&quot;</div><div class="line">    echo &quot;Commit aborted.&quot;</div><div class="line">    exit $&#123;EXIT_CODE&#125;</div><div class="line">fi</div></pre></td></tr></table></figure>
<h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><p>当然除了git commit hook外，还有其它的许多hook，详见<a href="http://git-scm.com/docs/githooks" target="_blank" rel="external">http://git-scm.com/docs/githooks</a>，如git push hook还可以用来添加自动部署测试机的功能，剩下的就靠自己YY了。</p>
</span>
      
    </div>

    <footer class="post-footer">

      
        <div class="post-nav">
          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/11/17/scliuyang/svg-advanced/" rel="prev">SVG进阶教程</a>
            
          </div>

          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/10/21/HeOH/xg-htmlhint-for-vim/" rel="next">Vim使用xg-htmlhint配置教程</a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
  <a class="jiathis_button_tsina"></a>
  <a class="jiathis_button_tqq"></a>
  <a class="jiathis_button_weixin"></a>
  <a class="jiathis_button_cqq"></a>
  <a class="jiathis_button_douban"></a>
  <a class="jiathis_button_renren"></a>
  <a class="jiathis_button_qzone"></a>
  <a class="jiathis_button_kaixin001"></a>
  <a class="jiathis_button_copy"></a>
  <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank"></a>
  <a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript" >
  var jiathis_config={
    hideMore:false
  }
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
<!-- JiaThis Button END -->

      
    </div>
  </div>

 </div>

        

        
          <div class="comments" id="comments">
            <div id="SOHUCS" sid="" ></div>
          </div>
        
      </div>

      
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <a href="https://github.com/xgfe" target="_blank"><img class="site-author-image" src="http://p0.meituan.net/xgfe/082a9624ba5ae8602150a2d43968463e49348.png" alt="xgfe" itemprop="image"/></a>
          <p class="site-author-name" itemprop="name">xgfe</p>
        </div>
        <p class="site-description motion-element" itemprop="description">xgfe's blog. 鲜果前端的技术博客，鲜果前端研发部官方博客。前端基础技术研究：html, html5, javascript, css, css3；前端框架研究：angularJs, react, react native.</p>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">89</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          <div class="site-state-item site-state-categories">
            
              <span class="site-state-item-count">37</span>
              <span class="site-state-item-name">作者</span>
              
          </div>

          <div class="site-state-item site-state-tags">
            <a href="/tags">
              <span class="site-state-item-count">131</span>
              <span class="site-state-item-name">标签</span>
              </a>
          </div>

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" target="_blank" rel="alternate">
              <i class="menu-item-icon icon-next-feed"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/xgfe" target="_blank">GitHub</a>
              </span>
            
          
        </div>

        
        

        <div class="links-of-author motion-element">
          
        </div>

      </section>

      
        <section class="post-toc-wrap sidebar-panel-active">
          <div class="post-toc-indicator-top post-toc-indicator"></div>
          <div class="post-toc">
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Git-Hook"><span class="nav-number">1.</span> <span class="nav-text">Git Hook</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#pre-commit"><span class="nav-number">1.1.</span> <span class="nav-text">pre-commit</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#pre-commit-示例代码"><span class="nav-number">1.2.</span> <span class="nav-text">pre-commit 示例代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他"><span class="nav-number">1.3.</span> <span class="nav-text">其他</span></a></li></ol></li></ol></div>
            
          </div>
          <div class="post-toc-indicator-bottom post-toc-indicator"></div>
        </section>
      

    </div>
  </aside>


    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner"> <div class="copyright" >
  
  &copy; &nbsp; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="icon-next-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">xgfe</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" target="_blank" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


 </div>
    </footer>

    <div class="back-to-top"></div>
  </div>

  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  
  
    <script type="text/javascript"> 
(function(){ 
var appid = 'cysWiXvkm'; 
var conf = 'prod_fc970dbe85103c7a79b2c4f3dc7fb190'; 
var width = window.innerWidth || document.documentElement.clientWidth; 
if (width < 960) { 
window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("http://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); </script>
    

  


  
  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>
  <script type="text/javascript" src="/js/fancy-box.js?v=0.4.5.1"></script>


  <script type="text/javascript" src="/js/helpers.js?v=0.4.5.1"></script>
  

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/js/motion_global.js?v=0.4.5.1" id="motion.global"></script>




  <script type="text/javascript" src="/js/nav-toggle.js?v=0.4.5.1"></script>
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  
<script type="text/javascript" src="/js/bootstrap.scrollspy.js?v=0.4.5.1" id="bootstrap.scrollspy.custom"></script>


<script type="text/javascript" id="sidebar.toc.highlight">
  $(document).ready(function () {
    var tocSelector = '.post-toc';
    var $tocSelector = $(tocSelector);
    var activeCurrentSelector = '.active-current';

    $tocSelector
      .on('activate.bs.scrollspy', function () {
        var $currentActiveElement = $(tocSelector + ' .active').last();

        removeCurrentActiveClass();
        $currentActiveElement.addClass('active-current');

        $tocSelector[0].scrollTop = $currentActiveElement.position().top;
      })
      .on('clear.bs.scrollspy', function () {
        removeCurrentActiveClass();
      });

    function removeCurrentActiveClass () {
      $(tocSelector + ' ' + activeCurrentSelector)
        .removeClass(activeCurrentSelector.substring(1));
    }

    function processTOC () {
      getTOCMaxHeight();
      toggleTOCOverflowIndicators();
    }

    function getTOCMaxHeight () {
      var height = $('.sidebar').height() -
                   $tocSelector.position().top -
                   $('.post-toc-indicator-bottom').height();

      $tocSelector.css('height', height);

      return height;
    }

    function toggleTOCOverflowIndicators () {
      tocOverflowIndicator(
        '.post-toc-indicator-top',
        $tocSelector.scrollTop() > 0 ? 'show' : 'hide'
      );

      tocOverflowIndicator(
        '.post-toc-indicator-bottom',
        $tocSelector.scrollTop() >= $tocSelector.find('ol').height() - $tocSelector.height() ? 'hide' : 'show'
      )
    }

    $(document).on('sidebar.motion.complete', function () {
      processTOC();
    });

    $('body').scrollspy({ target: tocSelector });
    $(window).on('resize', function () {
      if ( $('.sidebar').hasClass('sidebar-active') ) {
        processTOC();
      }
    });

    onScroll($tocSelector);

    function onScroll (element) {
      element.on('mousewheel DOMMouseScroll', function (event) {
          var oe = event.originalEvent;
          var delta = oe.wheelDelta || -oe.detail;

          this.scrollTop += ( delta < 0 ? 1 : -1 ) * 30;
          event.preventDefault();

          toggleTOCOverflowIndicators();
      });
    }

    function tocOverflowIndicator (indicator, action) {
      var $indicator = $(indicator);
      var opacity = action === 'show' ? 0.4 : 0;
      $indicator.velocity ?
        $indicator.velocity('stop').velocity({
          opacity: opacity
        }, { duration: 100 }) :
        $indicator.stop().animate({
          opacity: opacity
        }, 100);
    }

  });
</script>

<script type="text/javascript" id="sidebar.nav">
  $(document).ready(function () {
    var html = $('html');
    var TAB_ANIMATE_DURATION = 200;
    var hasVelocity = $.isFunction(html.velocity);

    $('.sidebar-nav li').on('click', function () {
      var item = $(this);
      var activeTabClassName = 'sidebar-nav-active';
      var activePanelClassName = 'sidebar-panel-active';
      if (item.hasClass(activeTabClassName)) {
        return;
      }

      var currentTarget = $('.' + activePanelClassName);
      var target = $('.' + item.data('target'));

      hasVelocity ?
        currentTarget.velocity('transition.slideUpOut', TAB_ANIMATE_DURATION, function () {
          target
            .velocity('stop')
            .velocity('transition.slideDownIn', TAB_ANIMATE_DURATION)
            .addClass(activePanelClassName);
        }) :
        currentTarget.animate({ opacity: 0 }, TAB_ANIMATE_DURATION, function () {
          currentTarget.hide();
          target
            .stop()
            .css({'opacity': 0, 'display': 'block'})
            .animate({ opacity: 1 }, TAB_ANIMATE_DURATION, function () {
              currentTarget.removeClass(activePanelClassName);
              target.addClass(activePanelClassName);
            });
        });

      item.siblings().removeClass(activeTabClassName);
      item.addClass(activeTabClassName);
    });

    $('.post-toc a').on('click', function (e) {
      e.preventDefault();
      var targetSelector = escapeSelector(this.getAttribute('href'));
      var offset = $(targetSelector).offset().top;
      hasVelocity ?
        html.velocity('stop').velocity('scroll', {
          offset: offset  + 'px',
          mobileHA: false
        }) :
        $('html, body').stop().animate({
          scrollTop: offset
        }, 500);
    });

    // Expand sidebar on post detail page by default, when post has a toc.
    var $tocContent = $('.post-toc-content');
    if (isDesktop() && CONFIG.sidebar === 'post') {
      if ($tocContent.length > 0 && $tocContent.html().trim().length > 0) {
        displaySidebar();
      }
    }
  });
</script>



  <script type="text/javascript">
    $(document).ready(function () {
      if (CONFIG.sidebar === 'always') {
        displaySidebar();
      }
      if (isMobile()) {
        FastClick.attach(document.body);
      }
    });
  </script>

  

  
  

  
  <script type="text/javascript" src="/js/lazyload.js"></script>
  <script type="text/javascript">
    $(function () {
      $("#posts").find('img').lazyload({
        placeholder: "/images/loading.gif",
        effect: "fadeIn"
      });
    });
  </script>

  <!-- google search, added by felix -->
  <script>
      $('#gg-form').on('submit', function(e) {
        var keyword = $.trim($(this).find('#gg-search-input').val());
        if (keyword) {
          location.href = 'https://www.google.com.hk/?gfe_rd=cr&ei=hXw8VpjtHuLC8AeSuIjQAg&gws_rd=ssl#safe=strict&q='+encodeURIComponent(keyword)+'+site:xgfe.github.io';
        }
        return false;
      });
  </script>
  <!-- baidu 站长自动推送 -->
  <script>
  (function(){
      var bp = document.createElement('script');
      bp.src = '//push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>
</body>
</html>
